<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
</head>
<body>
	
</body>

<script>
/*
	var arr=["hello","world"];
	var Blob=new Blob(["hello","world"],{"type" : "text/xml"});
	console.log(Blob); 
*/

/*
	var arr=["hello","world"];
	var Blob=new Blob(["hello","world"],{"type" : "text/xml"});
	var newBlob=Blob.slice(0,5);//切割 >=0  <5 
	console.log(newBlob); 
*/



/*
//把type array 转换成Blob对象
var str ="asdabc";
var arr=[];
for(var i=0;i<str.length;i++){
	arr[i]=str.charCodeAt(i);//转换成ASCLL码
}
console.log(arr);

var array=new Uint8Array(arr);
console.log(array);

var blob=new Blob([array],{'type':'text/plain'});
console.log(blob);

var reader=new FileReader();
reader.readAsText(blob,'utf-8');//解析
 reader.onload=function(e){
 	//console.log(e.target.result);
 	var data=e.target.result;//这是转换后又转换回来 原文
 	var blob=new Blob([data]);
 	var a=document.createElement("a");
 	a.innerHTML="点击下载";
 	a.href=window.URL.createObjectURL(blob);
 	document.body.appendChild(a);
 	a.onclick=function(){
 		a.download='a.txt';//下载文件，doc文件
 	}

 }
 */


var blob= new Blob(["我们都是好孩子"],{type:"text/plain"});
var reader= new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload=function(e){
	var r=e.target.result;
	var buffer=new Uint8Array(r);//转换编码格式 Uint8Array

	reader.readAsArrayBuffer(new Blob(buffer),'utf-8');
	reader.onload=function(){
		var reader=new FileReader();
		reader.readAsText(blob,'utf-8');//解析为utf-8编码
		reader.onload=function(e){
			console.log(e.target.result)
		}
	}
} 
//可以把 file 转换成Blob,arraybuffer 转换 Blob
//可以利用 filereader解析file,blob,arraybuffer
</script>
</html>